package tj.eskhata.pos.services;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.hibernate.criterion.Criterion;

import tj.eskhata.pos.common.SBRate;
import tj.eskhata.pos.dao.AccDao;
import tj.eskhata.pos.dao.AccTargetDao;
import tj.eskhata.pos.dao.BankDao;
import tj.eskhata.pos.dao.CertTypeDao;
import tj.eskhata.pos.dao.CertificateDao;
import tj.eskhata.pos.dao.ClPartDao;
import tj.eskhata.pos.dao.ClPointDao;
import tj.eskhata.pos.dao.ClientDao;
import tj.eskhata.pos.dao.CountryDao;
import tj.eskhata.pos.dao.GenericDao;
import tj.eskhata.pos.dao.PsDoctransDao;
import tj.eskhata.pos.dao.RegionDao;
import tj.eskhata.pos.dao.SostDao;
import tj.eskhata.pos.dao.SprNpDao;
import tj.eskhata.pos.dao.SprPaySystemDao;
import tj.eskhata.pos.dao.SprvalDao;
import tj.eskhata.pos.dao.StatusDao;
import tj.eskhata.pos.dao.TarifDao;
import tj.eskhata.pos.dao.TownDao;
import tj.eskhata.pos.dao.TypeAccDao;
import tj.eskhata.pos.dao.UserDao;
import tj.eskhata.pos.domain.Acc;
import tj.eskhata.pos.domain.AccTarget;
import tj.eskhata.pos.domain.Bank;
import tj.eskhata.pos.domain.CertType;
import tj.eskhata.pos.domain.Certificate;
import tj.eskhata.pos.domain.ClPart;
import tj.eskhata.pos.domain.ClPoint;
import tj.eskhata.pos.domain.Client;
import tj.eskhata.pos.domain.Country;
import tj.eskhata.pos.domain.PsDoctrans;
import tj.eskhata.pos.domain.Region;
import tj.eskhata.pos.domain.Sost;
import tj.eskhata.pos.domain.SprNp;
import tj.eskhata.pos.domain.SprPaySystem;
import tj.eskhata.pos.domain.Sprval;
import tj.eskhata.pos.domain.Status;
import tj.eskhata.pos.domain.Tarif;
import tj.eskhata.pos.domain.Town;
import tj.eskhata.pos.domain.TypeAcc;
import tj.eskhata.pos.domain.User;

public class PosServiceImpl implements PosService {

  //private CheeseDao cheeseDao;

  //private DiscountDao discountDao;
	
  private AccDao accDao;
  private AccTargetDao accTargetDao;
  private BankDao bankDao;
  private CertificateDao certificateDao;
  private CertTypeDao certTypeDao;
  private ClientDao clientDao;
  private ClPartDao clPartDao;
  private ClPointDao clPointDao;
  private CountryDao countryDao;
  private PsDoctransDao psDoctransDao;
  private RegionDao regionDao;
  private SostDao sostDao;
  private SprPaySystemDao sprPaySystemDao;
  private SprvalDao sprvalDao;
  private StatusDao statusDao;
  private SprNpDao sprNpDao;
  private TarifDao tarifDao;
  private TownDao townDao;
  private TypeAccDao typeAccDao;
  private UserDao userDao;  
  private GenericDao genericDao;

  public PosServiceImpl() {
  }

  public <T> T load(Class<T> type, long id) {
    return genericDao.load(type, id);
  }
  
  public <T> List<T> findByCriteria(Class<T> type, Criterion... criterion){
	return genericDao.findByCriteria(type, criterion);
  }
  //ACC  
  public List<Acc> findAllAccs() {
    return accDao.findAll();
  }
  public List<Acc> findByCriteriaAcc(Criterion... criterion)
  {
	return accDao.findByCriteria(criterion);  
  }
  public void saveAcc(Acc acc) {
	    accDao.save(acc);
  }  
  public void deleteAcc(Acc acc) {
	   accDao.delete(acc);
  }
  public AccDao getAccDao() {
	    return accDao;
  }
  public void setAccDao(AccDao accDao) {
	   this.accDao = accDao;
  }
  public Long getAccPsAcc(String codeAcc, Long paySysId, Long ftMoneyId, Long partId, Long accTarget){
	  return accDao.getAccPs(codeAcc, paySysId, ftMoneyId, partId, accTarget);
  }
  public Long getAcc(String codeAcc, Long ftMoneyId, Long partId,Long accPartId, Long accPointId){
	  return accDao.getAcc(codeAcc, ftMoneyId, partId, accPartId, accPointId);
  }
  
  //AccTarget
  public List<AccTarget> findAllAccTarget() {
	  return accTargetDao.findAll();
  }
  public void saveAccTarget(AccTarget accTarget) {
	  accTargetDao.save(accTarget);
  }  
  public void deleteAccTarget(AccTarget accTarget) {
	  accTargetDao.delete(accTarget);
  }
  public AccTargetDao getAccTargetDao() {
	    return accTargetDao;
  }
  public void setAccTargetDao(AccTargetDao accTargetDao) {
	   this.accTargetDao = accTargetDao;
  }
  //Bank
  public List<Bank> findAllBanks() {
	  return bankDao.findAll();
  }
  public void saveBank(Bank bank) {
	  bankDao.save(bank);
  }  
  public void deleteBank(Bank bank) {
	   bankDao.delete(bank);
  }
  public BankDao getBankDao() {
	    return bankDao;
  }
  public void setBankDao(BankDao bankDao) {
	   this.bankDao = bankDao;
  }
  //Certificate  
  public List<Certificate> findAllCertificates() {
	  return certificateDao.findAll();
  }
  public List<Certificate> findByCriteriaCertificate(Criterion... criterion)
  {
	return certificateDao.findByCriteria(criterion);  
  }
  public void saveCertificate(Certificate certificate) {
	  certificateDao.save(certificate);
  }
  public Certificate saveCertificateExt(Certificate certificate) {
	  return certificateDao.saveExt(certificate);
  }
  
  public void deleteCertificate(Certificate certificate) {
	   certificateDao.delete(certificate);
  }
  public CertificateDao getCertificateDao() {
	    return certificateDao;
  }
  public void setCertificateDao(CertificateDao certificateDao) {
	   this.certificateDao = certificateDao;
  }
  
  //CertType
  public List<CertType> findAllCertTypes() {
	  return certTypeDao.findAll();
  }
  public List<CertType> findByCriteriaCertType(Criterion... criterion)
  {
	return certTypeDao.findByCriteria(criterion);  
  }
  public void saveCertType(CertType certType) {
	  certTypeDao.save(certType);
  }  
  public void deleteCertType(CertType certType) {
	   certTypeDao.delete(certType);
  }
  public CertTypeDao getCertTypeDao() {
	    return certTypeDao;
  }
  public void setCertTypeDao(CertTypeDao certTypeDao) {
	   this.certTypeDao = certTypeDao;
  }
  
  //Client
  public List<Client> findAllClients() {
	  return clientDao.findAll();
  }
  public List<Client> criteriaByNameClient(String name,String pasp , Integer num) {
	  return clientDao.criteriaByName(name,pasp,num);
  }
  public List<Client> findByCriteriaClient(Criterion... criterion)
  {
	return clientDao.findByCriteria(criterion);  
  }
  public void saveClient(Client client) {
	  clientDao.save(client);
  } 
  public Client saveClientExt(Client client) {
	  return clientDao.saveExt(client);
  } 
  public void deleteClient(Client client) {
	   clientDao.delete(client);
  }
  public ClientDao getClientDao() {
	    return clientDao;
  }
  public void setClientDao(ClientDao clientDao) {
	   this.clientDao = clientDao;
  }
 
  
  //ClPart
  public List<ClPart> findAllClParts() {
	  return clPartDao.findAll();
  }
  public List<ClPart> findByCriteriaClPart(Criterion... criterion)
  {
	return clPartDao.findByCriteria(criterion);  
  }
  public void saveClPart(ClPart clPart) {
	  clPartDao.save(clPart);
  }  
  public void deleteClPart(ClPart clPart) {
	   clPartDao.delete(clPart);
  }
  public ClPartDao getClPartDao() {
	    return clPartDao;
  }
  public void setClPartDao(ClPartDao clPartDao) {
	   this.clPartDao = clPartDao;
  }
  public Date getOpDateClPart(Long clPartId){
	  return clPartDao.getOpDate(clPartId);
  }
  
  //ClPoint
  public List<ClPoint> findAllClPoints() {
	  return clPointDao.findAll();
  }
  public List<ClPoint> findByCriteriaClPoint(Criterion... criterion)
  {
	return clPointDao.findByCriteria(criterion);  
  }
  public void saveClPoint(ClPoint clPoint) {
	  clPointDao.save(clPoint);
  }  
  public void deleteClPoint(ClPoint clPoint) {
	   clPointDao.delete(clPoint);
  }
  public ClPointDao getClPointDao() {
	    return clPointDao;
  }
  public void setClPointDao(ClPointDao clPointDao) {
	   this.clPointDao = clPointDao;
  }
  
  //Country
  public List<Country> findAllCountries() {
	    return countryDao.findAll();
  }
  public List<Country> findAllCountries(String order) {
	    return countryDao.findAll(order);
}
  public List<Country> findByCriteriaCountry(Criterion... criterion)
  {
	return countryDao.findByCriteria(criterion);  
  }
  public void saveCountry(Country country) {
	  countryDao.save(country);
  }  
  public void deleteCountry(Country country) {
	  countryDao.delete(country);
  }
  public CountryDao getCountryDao() {
	   return countryDao;
  }
  public void setCountryDao(CountryDao countryDao) {
	   this.countryDao = countryDao;
  }
  
  //PsDocuments
  public List<PsDoctrans> findAllPsDoctrans(){	  
	  return psDoctransDao.findAll();
  }
  public List<PsDoctrans> findByCriteriaPsDoctrans(Criterion... criterion){
	  return psDoctransDao.findByCriteria(criterion);
  }  
  public List<Long> getDosyeClientsPsDoctrans(Date bdate,Date edate,Long partId, Long sostId){
	  return psDoctransDao.getDosyeClients(bdate, edate, partId, sostId);
  }
  public Object getRepPSysPsDoctrans(Date bdate,Date edate,Long point, Long part, Long pSysId, Long valId, String sostCode){
	return psDoctransDao.getRepPSys(bdate, edate, point, part, pSysId, valId, sostCode);  
  }
  public void savePsDoctrans(PsDoctrans psDocument){
	  psDoctransDao.save(psDocument);
  }
  public PsDoctrans savePsDoctransExt(PsDoctrans psDocument){
	  return psDoctransDao.saveExt(psDocument);
  }
  public void deletePsDoctrans(PsDoctrans psDocument){
	  psDoctransDao.delete(psDocument);
  }
  public void setPsDoctransDao(PsDoctransDao psDoctransDao){
	  this.psDoctransDao=psDoctransDao;
  }
  public PsDoctransDao getPsDoctransDao(){
	  return psDoctransDao;
  }
  public void toConfirm(PsDoctrans object,Date datConf, Long userId){
	  psDoctransDao.toConfirm(object, datConf, userId);
  }
  
  public List<PsDoctrans> getJornalPsDoctrans(Date bdate,Date edate,Long point, Long part){
	  return psDoctransDao.getJornal( bdate, edate, point, part);
  }
  public List<PsDoctrans> getCommitedPsDoctrans(Date bdate,Date edate,Long point, Long part, String clName, String docNum, Long userId){
	  return psDoctransDao.getCommited( bdate, edate, point, part, clName, docNum, userId);
  }
  public int validateCancelPsDoctrans(PsDoctrans object){
	  return psDoctransDao.validateCancel(object);
  }
  public void toCancelPsDoctrans(PsDoctrans object, Long userId){
	  psDoctransDao.toCancel(object, userId);
  }
  
  //Region
  public List<Region> findAllRegions() {
	  return regionDao.findAll();
  }
  public List<Region> findByCriteriaRegion(Criterion... criterion)
  {
	return regionDao.findByCriteria(criterion);  
  }
  public void saveRegion(Region region) {
	  regionDao.save(region);
  }  
  public void deleteRegion(Region region) {
	  regionDao.delete(region);
  }
  public RegionDao getRegionDao() {
	    return regionDao;
  }
  public void setRegionDao(RegionDao regionDao) {
	   this.regionDao = regionDao;
  }
  
  //Sost
  public List<Sost> findAllSosts() {
	  return sostDao.findAll();
  }
  public List<Sost> findByCriteriaSost(Criterion... criterion)
  {
	return sostDao.findByCriteria(criterion);  
  }
  public void saveSost(Sost sost) {
	  sostDao.save(sost);
  }  
  public void deleteSost(Sost sost) {
	   sostDao.delete(sost);
  }
  public SostDao getSostDao() {
	    return sostDao;
  }
  public void setSostDao(SostDao sostDao) {
	   this.sostDao = sostDao;
  }
  
  public Sost getSost(String code){
	  return sostDao.getSost( code);
  }
  
  //SprPaySystem
  public List<SprPaySystem> findAllSprPaySystems() {
	  return sprPaySystemDao.findAll();
  }
  public List<SprPaySystem> findByCriteriaPaySystem(Criterion... criterion)
  {
	return sprPaySystemDao.findByCriteria(criterion);  
  }
  public void saveSprPaySystem(SprPaySystem sprPaySystem) {
	  sprPaySystemDao.save(sprPaySystem);
  }  
  public void deleteSprPaySystem(SprPaySystem sprPaySystem) {
	   sprPaySystemDao.delete(sprPaySystem);
  }
  public SprPaySystemDao getSprPaySystemDao() {
	    return sprPaySystemDao;
  }
  public void setSprPaySystemDao(SprPaySystemDao sprPaySystemDao) {
	   this.sprPaySystemDao = sprPaySystemDao;
  }
  
  //Sprval
  public List<Sprval> findAllSprvals() {
	  return sprvalDao.findAll();
  }
  public List<Sprval> findByCriteriaVal(Criterion... criterion)
  {
	return sprvalDao.findByCriteria(criterion);  
  }
  public void saveSprval(Sprval sprval) {
	  sprvalDao.save(sprval);
  }  
  public void deleteSprval(Sprval sprval) {
	   sprvalDao.delete(sprval);
  }
  public SprvalDao getSprvalDao() {
	    return sprvalDao;
  }
  public void setSprvalDao(SprvalDao sprvalDao) {
	   this.sprvalDao = sprvalDao;
  }
  public SBRate GetSBRateSprval(Long ftMoney, Date onDate){
	  return sprvalDao.GetSBRate(ftMoney, onDate);
  }
  
//SprNp
  public List<SprNp> findAllSprNps() {
	  return sprNpDao.findAll();
  }
  public List<SprNp> findByCriteriaSprNp(Criterion... criterion)
  {
	return sprNpDao.findByCriteria(criterion);  
  }
  public void saveSprNp(SprNp sprNp) {
	  sprNpDao.save(sprNp);
  }  
  public void deleteSprNp(SprNp sprNp) {
	   sprNpDao.delete(sprNp);
  }
  public SprNpDao getSprNpDao() {
	    return sprNpDao;
  }
  public void setSprNpDao(SprNpDao sprNpDao) {
	   this.sprNpDao = sprNpDao;
  }
  
  //Status
  public List<Status> findAllStatuses() {
	    return statusDao.findAll();
	  }
  public List<Status> findByCriteriaStatus(Criterion... criterion)
  {
	return statusDao.findByCriteria(criterion);  
  }
  public void saveStatus(Status status) {
	  	statusDao.save(status);
  }  
  public void deleteStatus(Status status) {
	  	statusDao.delete(status);
  }
  public StatusDao getStatusDao() {
	  	return statusDao;
  }
  public void setStatusDao(StatusDao statusDao) {
	  	this.statusDao = statusDao;
  }

  //Tarif
  public BigDecimal getSumKomiss(BigDecimal summa_, Long tarif_, Date date_, ClPart part_, Sprval sprVal_){
	  return tarifDao.getSumKomiss( summa_, tarif_, date_, part_, sprVal_);
  }
  public TarifDao getTarifDao() {
	    return tarifDao;
  }
  public void setTarifDao(TarifDao tarifDao) {
	    this.tarifDao = tarifDao;
  }
  
  //Town  
  public List<Town> findAllTowns() {
	  return townDao.findAll();
  }
  public List<Town> findByCriteriaTown(Criterion... criterion)
  {
	return townDao.findByCriteria(criterion);  
  }
  public void saveTown(Town town) {
	  townDao.save(town);
  }  
  public void deleteTown(Town town) {
	   townDao.delete(town);
  }
  public TownDao getTownDao() {
	    return townDao;
  }
  public void setTownDao(TownDao townDao) {
	   this.townDao = townDao;
  }
  
  //TypeAcc
  public List<TypeAcc> findAllTypeAccs() {
	  return typeAccDao.findAll();
  }
  public void saveTypeAcc(TypeAcc typeAcc) {
	  typeAccDao.save(typeAcc);
  }  
  public void deleteTypeAcc(TypeAcc typeAcc) {
	   typeAccDao.delete(typeAcc);
  }
  public TypeAccDao getTypeAccDao() {
	    return typeAccDao;
  }
  public void setTypeAccDao(TypeAccDao typeAccDao) {
	   this.typeAccDao = typeAccDao;
  }
  
  //User
  public List<User> findAllUsers() {
	  return userDao.findAll();
  }
  public List<User> findByCriteriaUser(Criterion... criterion)
  {
	return userDao.findByCriteria(criterion);  
  }
  public void saveUser(User user) {
	  userDao.save(user);
  }  
  public void deleteUser(User user) {
	   userDao.delete(user);
  }
  public UserDao getUserDao() {
	    return userDao;
  }
  public void setUserDao(UserDao userDao) {
	   this.userDao = userDao;
  }
  public boolean isUserInGroupUser(User user, String groupCode){
	  return userDao.isUserInGroup(user, groupCode);
  }   

/*
  public void saveDiscounts(List<Discount> discounts) {
    if (discounts == null) {
      return;
    }
    for (Discount discount : discounts) {
      discountDao.save(discount);
    }
  }
*/
  
  public GenericDao getGenericDao() {
    return genericDao;
  }
  public void setGenericDao(GenericDao genericDao) {
    this.genericDao = genericDao;
  }

}
